﻿using System.Linq;
using System.ComponentModel;
using WindMill.Models.Controladoria;
using WindMill.Services;


namespace WindMill.Models.Cadastro
{
    public partial class Pessoa : INotifyPropertyChanged, INotifyPropertyChanging
    {

        private ClassificacaoCadastro _classCadastro;
        public ClassificacaoCadastro ClassificacaoCadastro
        {
            get
            {
                if (CodClassCadastro == null)
                    return null;

                if (_classCadastro == null || _classCadastro.Id != CodClassCadastro)
                {
                    var ctx = OracleConnectionPool.GetPool().GetDbContext<EDMControladoria>() as EDMControladoria;

                    _classCadastro = ctx.ClassificacaoCadastros.SingleOrDefault(c => c.Id == CodClassCadastro);
                }
                return _classCadastro;

            }
            set
            {
                OnPropertyChanging("ClassificacaoCadastro");
                _classCadastro = value;
                CodClassCadastro = value != null ? value.Id : (int?) null;
                OnPropertyChanged("ClassificacaoCadastro");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public void OnPropertyChanged(string property)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public void OnPropertyChanging(string property)
        {
            if (PropertyChanging != null)
            {
                PropertyChanging(this, new PropertyChangingEventArgs(property));
            }
        }

        public override string ToString()
        {
            return Nome;
        }
    }
}
